package ch10;

/**
 * @author oldliu
 * @since 1.0
 */
public class BubbleSort {
    public static void main(String[] args) {
        int[] a = {8, 66, 110, 112, 114, 119, 101, 88};
        int[] c = new int[a.length];//放位置
        int d = 0;
        //初始化位置坐标
        for (int i = 0; i < a.length; i++) {
            c[i] = i+1;//1,2,3,初始化下标。。。
        }
        for (int i = 0; i < a.length; i++) {
            for (int b = 0; b < a.length-1-i; b++) {
                if (a[b] >a[b + 1]) {
                    d = a[b];
                    a[b] = a[b + 1];
                    a[b + 1] = d;
                    //C对应的位置也换
                    int weizhi=c[b];
                    c[b]=c[b+1];
                    c[b+1]=weizhi;
                }
            }
        }
        System.out.println("排序后和对应的位置是：");
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i] + "\t");
        }
        System.out.println();
        for (int i = 0; i < c.length; i++) {
            System.out.print(c[i] + "\t");
        }


    }
}
